package com.nibianplus.base;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import com.nibianplus.volley.VolleyHttpClient;
import org.json.JSONObject;

public abstract class BaseFragment extends Fragment implements BaseObjectListener {

	protected BaseObject dataObject;
	public abstract void refreshUI(BaseObject object, int what);
	protected abstract BaseObject createDataObject();


	public void dataObjectChanged(BaseObject object, int what) {
		refreshUI(object, what);
	}


	public void dataObjectFailed(BaseObject dataObject, int what, JSONObject response) {

	}

	public String getTagName() {
		return getClass().getName();
	}

	public BaseObject getDataObject() {
		return dataObject;
	}

	@Override
	final public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		onCreateHE(savedInstanceState);
	}

	public void onCreateHE(Bundle savedInstanceState) {
		dataObject = createDataObject();
		dataObject.setListener(this);
		dataObject.refresh();
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		VolleyHttpClient.cancalAll(getTagName());
	}
}